<?php

class Workset_View_Helper_AttachmentPicture extends Zend_View_Helper_HtmlElement {

    const MAX_WIDTH = 400;

    const MAX_HEIGHT = 400;

    public function attachmentPicture($file, $attrs = array()) {

        if (isset($file['width']) && isset($file['height'])) {
            if ($file['width'] > self::MAX_WIDTH) {
                $w = self::MAX_WIDTH;
                $h = ($w * $file['height']) / $file['width'];

                $file['width'] = $w;
                $file['height'] = $h;
            }

            if ($file['height'] > self::MAX_HEIGHT) {
                $h = self::MAX_HEIGHT;
                $w = ($h * $file['width']) / $file['height'];

                $file['height'] = $h;
                $file['width'] = $w;
            }

            $attrs['width'] = $file['width'];
            $attrs['height'] = $file['height'];
        }

        $attrs += array(
            'id' => $file['id'],
            'src' => $file['shortpath'],
        );

        return '<img '.$this->_htmlAttribs($attrs).' />';

    }

}

?>